import BASE_URL from "./path";
import { mapMutations } from 'vuex'
let mixin = {
	data() {
		return {
			is_login:true,
			tel:'',
			active_id:BASE_URL.acitveId,
			button_type:-1
		};
	},
	onLoad(options) { 
	    
	},
	methods: {
		...mapMutations(['setShowLogin']),
		async getUserInfo(bl) {
			const res = await this.$http({
				  url:'user/info',
				  method:'get',
				  data:{
					  activity_id:BASE_URL.acitveId
				  }
			 })
			 //console.log(res.data.status_code);
			//button_type 1未登录  2已登录未报名 3已报名3个作品以内 4已报名传玩了3个作品
			 if (res.data.status_code == 401) {
				 //未登录状态
				 if(bl) {
					 this.setShowLogin(true);
				 }
				 this.is_login = false;
				 this.button_type = 1
			 } else { 
				 this.is_login = true;
				 const data = res.data[0];
				 this.tel = data.mobile;
				 if (!data.company) {
					 //已登录未报名
					 this.button_type = 2;
				 } else {
					 if(data.num < 1) {
						 //已报名没有上传可以编辑
						 this.button_type = 5;
					 } else if(data.num < 3){
						  this.button_type = 3;
					 } else {
						 this.button_type = 4;
					 }
					 //已报名
				 }
			 }
			 //console.log(this.button_type);
			 return res.data[0];
		},
		checkLogin(){
			if(this.is_login) {
				return true;
			} else {
				this.$refs.loginx.show();
				return false;
			}
		},
		getInfo() {
			if(this.callbackLogin) {
				this.callbackLogin()
			}
		},
		toast(str) {
			uni.showToast({
				title:str,
				icon:"none"
			})
		},
		goDetail(id){
			uni.navigateTo({
				url:"/pages/detail/detail?id=" + id
			})
		},
		goIndex() {
			uni.navigateTo({
				url:'/pages/index/index'
			})
		},
		goShowBook () {
			uni.navigateTo({
				url:'/pages/showBook/showBook'
			})
		},
		goUp() {
			uni.navigateTo({
				url:'/pages/upLoadhs/upLoadhs'
			})
		},
		goSin() {
			// console.log('button_type',this.button_type);
			if(this.button_type == 3 || this.button_type == 4 || this.button_type == 5) {
				uni.navigateTo({
				  url:'/pages/editor/editor'
				})
			} else {
				uni.navigateTo({
				  url:'/pages/sigUP/sigUP'
				})
			}
		}
	}
}
export default mixin;
